/* pin_init.c */
#include "pin_init.h"

#include "hal_pctrl.h"

typedef struct
{
    PCTRL_Type *        port;
    uint32_t            pinid;
    PCTRL_PinMux_Type   pinmux;
} pin_init_conf_t;

const pin_init_conf_t pin_init_conf_arr[] =
{
    { PCTRLC, 6u, PCTRL_PinMux_Alt2 }, /* ptc6. uart1_rx. */
    { PCTRLC, 7u, PCTRL_PinMux_Alt2 }, /* ptc7. uart1_tx. */
    { PCTRLA, 0u, PCTRL_PinMux_GPIO }, /* pta0. gpio_output, buzzer. */
    { PCTRLA, 3u, PCTRL_PinMux_GPIO }, /* pta0. gpio_output, ble_disconnect. */
    { PCTRLB, 0u, PCTRL_PinMux_Alt2 }, /* ptb0. uart0_rx, ble_uart_rx. */
    { PCTRLB, 1u, PCTRL_PinMux_Alt2 }, /* ptb1. uart0_tx, ble_uart_tx. */
    { PCTRLB, 4u, PCTRL_PinMux_Alt2 }, /* ptb4. etmr0_ch4 output, motor0_pwm0. */
    { PCTRLB, 5u, PCTRL_PinMux_Alt2 }, /* ptb5. etmr0_ch5 output, motor0_pwm1. */
    { PCTRLC, 0u, PCTRL_PinMux_Alt2 }, /* ptc0. etmr0_ch0 output, motor1_pwm0. */
    { PCTRLC, 1u, PCTRL_PinMux_Alt2 }, /* ptc1. etmr0_ch1 output, motor1_pwm1. */
    { PCTRLB, 2u, PCTRL_PinMux_Alt2 }, /* ptb2. etmr1_ch0 output, motor2_pwm0. */
    { PCTRLB, 3u, PCTRL_PinMux_Alt2 }, /* ptb3. etmr1_ch1 output, motor2_pwm1. */
    { PCTRLD, 0u, PCTRL_PinMux_Alt2 }, /* ptd0. etmr0_ch2 output, motor3_pwm0. */
    { PCTRLD, 1u, PCTRL_PinMux_Alt2 }, /* ptd1. etmr0_ch3 output, motor3_pwm1. */
    { PCTRLA, 1u, PCTRL_PinMux_Alt4 }, /* pta1. spi2_sout, ws2812b. */
    { PCTRLA, 7u, PCTRL_PinMux_Analog }, /* pta7. adc0_se3, power sensor. */
};

void BOARD_InitBootPins(void)
{
    PCTRL_PinConf_Type pin_conf;

    pin_conf.EnableHighDriveStrength = true;
    pin_conf.EnablePassiveFilter = false;
    pin_conf.EnableSlowRate = false;
    pin_conf.PinPullMode = PCTRL_PinPullMode_Disabled;    
    for (uint32_t i = 0u; i < (sizeof(pin_init_conf_arr)/sizeof(pin_init_conf_arr[0])); i++)
    {
        pin_conf.PinMux = pin_init_conf_arr[i].pinmux;
        PCTRL_SetPinConf(pin_init_conf_arr[i].port, pin_init_conf_arr[i].pinid, &pin_conf);        
    }
#if 0
    /* ptc6. uart1_rx. */
    pin_conf.PinMux = PCTRL_PinMux_Alt2;
    pin_conf.EnableHighDriveStrength = false;
    pin_conf.EnablePassiveFilter = false;
    pin_conf.EnableSlowRate = false;
    pin_conf.PinPullMode = PCTRL_PinPullMode_Disabled;
    PCTRL_SetPinConf(PCTRLC, 6u, &pin_conf);

    /* ptc7. uart1_tx. */
    pin_conf.PinMux = PCTRL_PinMux_Alt2;
    pin_conf.EnableHighDriveStrength = false;
    pin_conf.EnablePassiveFilter = false;
    pin_conf.EnableSlowRate = false;
    pin_conf.PinPullMode = PCTRL_PinPullMode_Disabled;
    PCTRL_SetPinConf(PCTRLC, 7u, &pin_conf);
#endif
}

/* EOF. */

